import { IPagination } from '@/types/pagination'
import { useDayjsHelper } from '..'
import { Shortcuts } from 'naive-ui/es/date-picker/src/interface'
import { PaginationInfo } from 'naive-ui'

function useNaiveHelper() {
    const { getMonthRange, getWeekRange } = useDayjsHelper()

    const dateShortcuts: Shortcuts = {
        最近一周: () => {
            const [start, end] = getWeekRange(1)

            return [start, end]
        },
        最近一个月: () => {
            const [start, end] = getMonthRange(1)

            return [start, end]
        },
        最近三个月: () => {
            const [start, end] = getMonthRange(3)
            return [start, end]
        },
        最近半年: () => {
            const [start, end] = getMonthRange(6)

            return [start, end]
        },
        最近一年: () => {
            const [start, end] = getMonthRange(12)
            return [start, end]
        },
    }

    /**
     * @description 专门用来把本项目的分页格式转化成 naiveui 的 分页格式的适配器
     * @example  const initialState: IPagination = {
                    current: 1,
                    size: 10,
                    total: 1,
                }
                <n-data-table :columns="detectColumns" :pagination="toPagination(pagination)" :data="detectInfoList"
                    @page-change="getMonitorInfo"></n-data-table>
     */
    function toPagination(pagination: IPagination): Partial<PaginationInfo> {
        return {
            page: pagination.current,
            pageSize: pagination.size,
            itemCount: pagination.total,
        }
    }

    return {
        dateShortcuts,
        toPagination,
    }
}

export default useNaiveHelper
